import java.io.*;
import java.net.*;
import java.util.Date;

public class MyServer2 {

	public static void main(String[] args) throws IOException{
	
	DatagramSocket datagramSocket =new DatagramSocket(12345);
	
		while (true) {

			byte[] receiveBuf = new byte[1024];
			DatagramPacket packetIn = new
			DatagramPacket(receiveBuf, receiveBuf.length);
			datagramSocket.receive(packetIn);

			Dd readThread = new Dd();
			String response = readThread.getFile(receiveBuf.toString());
			byte[] responseBuf = response.getBytes();
			InetAddress senderIP = packetIn.getAddress();
			int senderPort = packetIn.getPort();
			DatagramPacket packetOut = new DatagramPacket(
			responseBuf, responseBuf.length,
			senderIP, senderPort);
			datagramSocket.send(packetOut);

			}
		}
	}

class Dd {
	
	public String getFile(String a) {
		
		try {
			RandomAccessFile raf = new RandomAccessFile(a, "r");
			
			try {
				return raf.readLine();
			} catch (IOException e) {
				return "Error reading file "+a;
			}
		} catch (FileNotFoundException e) {
			return "Error reading file "+a;
		}
		
		//return "";
	
	}
	
}	
